<?php include("../includes/header-member.php") ?>
<title>LazySwim</title>
</head>

<body>
<div id="page">
    <div id="page-top">
        <div id="page-bottom">
          <div id="header">
                <div id="header-info">
                    <h1>LAZYSWIM</h1>
                    <div class="description">Simplistic Swim System</div>
                </div>
				<!-- Header Goes Here -->
                <?php printHeader(); ?>
				<!-- Header Ends Here -->
                <div id="header-date">Today is <?php echo date('l, F jS, Y'); ?></div>
                <div id="header-cats">
				<!-- Welcome Message Starts Here -->
                    <ul>
					<?php include("../../includes/welcomeBar.php"); ?>
					</ul>
				<!-- Welcome Message Ends Here -->	
                </div>
            </div>
            <div id="main">

                <div id="sidebar">
                    <div class="sidebar-box">
                    <h3>Mail</h3>
                    <ul>
                        <li class="page_item"><a href="newMessage.php">New Message</a></li>
                        <li class="page_item"><a href="inbox.php">Inbox</a></li>
                        <li class="page_item"><a href="outbox.php">Outbox</a></li>
                    </ul>
                    </div>
                    <?php
					// include the corresponding navigation page
                    include("../../includes/navigation.php");
					?>    
                </div>

            <!-- main body -->
			
			<div class="featured-post"> 
			
				<div class="post-title"><h2>Outbox</h2></div>
				<div class="post-entry">
			
				<?php
				require_once("../includes/dbInfo.php");
				$user = $_SESSION['ls_userid'];

				$messages_sql = mysql_query("SELECT * from messages where senderID = '$user' ORDER BY timestamp DESC") 
					or die(mysql_error());

					echo "<br><table width=65% border=1 rules=rows cellpadding=10><tr>";
				echo "<th>Sent To</th><th>Date</th><th>Subject</th></tr>";

				while( $row = mysql_fetch_array($messages_sql)) {
					// fetch the sender for each message
					$receiver_sql = mysql_query("SELECT name from accounts where userID = '$row[receiverID]'") 
					or die(mysql_error()); 
					$receiver = mysql_fetch_row($receiver_sql);
					
					echo "<tr>";
					echo "<td><center>" . $receiver[0] . "</center></td>";
					echo "<td><center>" . $row[timestamp] . "</center></td>";
					echo "<td><center>";
					echo "<a href=\"viewMessage.php?msgID=" . $row[messageID] . "\">" 
						. $row[subject] . "</a></center></td>";
					echo "</tr>";
				}
				echo "</tr></table>";
				echo "</form>";
					
				?>
				</div>
			</div>

            <div class="clear"></div>

            </div>
			<!-- Footer Goes Here -->
            <?php include("../../includes/footer.php"); ?>
			<!-- Footer Ends Here -->
        </div>
    </div>
</div>
</body>
</html>